package fitness;

import java.io.Serializable;

import util.MyUtil;

public class BistableResult extends FitnessResult implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1022879943135901613L;
	public int bistable;
	public String solutions;
	public String testString;
	public double firstScore;
	public double changeCausedByInput1;
	public double changeCausedByInput2;
	public int nSuccess;

	public BistableResult(int bistalbe, String solutions, String testString) {
		this.bistable = bistalbe;
		this.solutions = solutions;
		this.testString = testString;
	}
    
	@Override
	public Double[] getDecomposition(){
		Double[] temp = new Double[]{(double) (bistable == 2 ? 1 : 0),firstScore,changeCausedByInput1,changeCausedByInput2};
		return temp;
	}
	
	@Override
	public String toString() {
		return MyUtil.doubleFormat(finalResult()) + "= "
				+ (bistable == 2 ? 1 : 0) + "+"
				+ MyUtil.doubleFormat(firstScore) + "+"
				+ MyUtil.doubleFormat(changeCausedByInput1) + "+"
				+ MyUtil.doubleFormat(changeCausedByInput2);
	}

//	public String toStringTristable() {
//		return MyUtil.doubleFormat(finalResultTristable()) + "= "
//				+ (bistable == 3 ? 1 : 0) + "+" + (bistable == 2 ? 0.1 : 0)
//				+ "+0.005*" + getNSolutions();
//	}
//
//	public double finalResultTristable() {
//		return (bistable == 3 ? 1.0f : 0) + (bistable == 2 ? 0.1f : 0) + 0.005
//				* getNSolutions();
//	}

	public int getNSolutions() {
		int count = 0;
		for (int i = 0; i < solutions.length(); i++) {
			if (solutions.charAt(i) == '{') {
				count++;
			}
		}
		return Math.max(0, count - 1);
	}

	@Override
	public double finalResult() {
		return (bistable == 2 ? 1 : 0) + firstScore + changeCausedByInput1
		+ changeCausedByInput2;
	}

	@Override
	public boolean goodSolution() {
		// TODO Auto-generated method stub
		return false;
	}
}
